import request from '@/router/axios'

/**
 * 查询登录用户子菜单
 * @param {number} id 菜单id
 * @returns 用户子菜单
 */
export function getMenu (id) {
  return request({
    url: '/api/manage/menu/userTree',
    params: { parentId: id },
    method: 'get'
  })
}

/**
 * 查询登录用户顶部菜单
 * @returns 用户顶部菜单
 */
export function getTopMenu () {
  return request({
    url: '/api/manage/menu/userTree',
    params: { type: 'top' },
    method: 'get'
  })
}

/**
 * 查询管理菜单列表
 * @param {string} clientId 客户端id
 * @param {boolean} lazy 是否懒加载
 * @param {number} parentId 父菜单id
 * @returns 菜单列表
 */
export function fetchMenuTree (clientId, lazy, parentId) {
  return request({
    url: `/api/manage/menu/clientTree/${clientId}`,
    method: 'get',
    params: { lazy, parentId }
  })
}

export function addObj (obj) {
  return request({
    url: '/api/manage/menu',
    method: 'post',
    data: obj
  })
}

export function getObj (id) {
  return request({
    url: '/api/manage/menu/' + id,
    method: 'get'
  })
}

export function delObj (id) {
  return request({
    url: '/api/manage/menu/' + id,
    method: 'delete'
  })
}

export function putObj (obj) {
  return request({
    url: '/api/manage/menu',
    method: 'put',
    data: obj
  })
}
